import { createRouter, createWebHistory, RouteRecordRaw } from 'vue-router';
import Home from '@/layouts/Home.vue';
import Login from '@/views/Login/Login.vue';
import PatientManager from '@/views/Page/RegistrationManagement/PatientManager.vue';
import Registration from '@/views/Page/RegistrationManagement/Registration.vue';
import DoctorData from '@/views/Page/DoctorManager/DoctorData.vue';
import PrescriptionManager from '@/views/Page/DoctorManager/PrescriptionManager.vue';
import WorkScheduleManager from '@/views/Page/DoctorManager/WorkScheduleManager.vue';
import DepartmentData from '@/views/Page/DepartmentManager/DepartmentData.vue';
import Medicine from '@/views/Page/MedicineManager/Medicine.vue';
import StatisticsMedicine from '@/views/Page/StatisticsManager/StatisticsMedicine.vue';
import StatisticsPatient from '@/views/Page/StatisticsManager/StatisticsPatient.vue';
import StatisticsRevenue from '@/views/Page/StatisticsManager/StatisticsRevenue.vue';
import JobTitleManager from '@/views/Page/OtherManager/JobTitleManager.vue';
import SpecialtyManager from '@/views/Page/OtherManager/SpecialtyManager.vue';
import Medical from '@/views/Page/MedicalTreatmentManagement/Medical.vue';
import Admission from '@/views/Page/Admission.vue';
import MedicineAdd from '@/views/Page/MedicineManager/MedicineAdd.vue';
import Ward from '@/views/Page/Ward.vue';
import Testing from '@/test/Testing.vue';

const routes: Array<RouteRecordRaw> = [
  {
    path: '/',
    name: "Login",
    component: Login,
    meta: { requiresAuth: false }
  },
  {
    path: '/Home',
    name: 'Home',
    component: Home,
    meta: { requiresAuth: true },
    children: [
      // 挂号管理
      {
        path: 'PatientManager',
        name: 'PatientManager',
        component: PatientManager,
        meta: { group: 'registration', title: '患者管理' }
      },
      {
        path: 'Registration',
        name: 'Registration',
        component: Registration,
        meta: { group: 'registration', title: '挂号管理' }
      },

      // 医生管理
      {
        path: 'DoctorData',
        name: 'DoctorData',
        component: DoctorData,
        meta: { group: 'doctor', title: '医生管理' }
      },
      {
        path: 'PrescriptionManager',
        name: 'PrescriptionManager',
        component: PrescriptionManager,
        meta: { group: 'doctor', title: '处方管理' }
      },
      {
        path: 'WorkScheduleManager',
        name: 'WorkScheduleManager',
        component: WorkScheduleManager,
        meta: { group: 'doctor', title: '排班管理' }
      },

      // 部门管理
      {
        path: 'DepartmentData',
        name: 'DepartmentData',
        component: DepartmentData,
        meta: { group: 'department', title: '科室管理' }
      },

      // 药品管理
      {
        path: 'Medicine',
        name: 'Medicine',
        component: Medicine,
        meta: { group: 'medicine', title: '药品列表' }
      },
      {
        path: 'MedicineAdd',
        name: 'MedicineAdd',
        component: MedicineAdd,
        meta: { group: 'medicine', title: '添加药品' }
      },

      // 统计管理
      {
        path: 'StatisticsMedicine',
        name: 'StatisticsMedicine',
        component: StatisticsMedicine,
        meta: { group: 'statistics', title: '药品统计' }
      },
      {
        path: 'StatisticsPatient',
        name: 'StatisticsPatient',
        component: StatisticsPatient,
        meta: { group: 'statistics', title: '患者统计' }
      },
      {
        path: 'StatisticsRevenue',
        name: 'StatisticsRevenue',
        component: StatisticsRevenue,
        meta: { group: 'statistics', title: '收入统计' }
      },

      // 住院管理
      {
        path: 'Admission',
        name: 'Admission',
        component: Admission,
        meta: { group: 'hospital', title: '入院管理' }
      },
      {
        path: 'Ward',
        name: 'Ward',
        component: Ward,
        meta: { group: 'hospital', title: '病房管理' }
      },

      // 其他管理
      {
        path: 'JobTitleManager',
        name: 'JobTitleManager',
        component: JobTitleManager,
        meta: { group: 'other', title: '职称管理' }
      },
      {
        path: 'SpecialtyManager',
        name: 'SpecialtyManager',
        component: SpecialtyManager,
        meta: { group: 'other', title: '专业管理' }
      },
      {
        path: 'Medical',
        name: 'Medical',
        component: Medical,
        meta: { group: 'other', title: '就医管理' }
      },
      {
        path: 'Testing',
        name: 'Testing',
        component: Testing,
        meta: { group: 'development', title: '测试页面' }
      }
    ]
  }
];

const router = createRouter({
  history: createWebHistory(import.meta.env.BASE_URL),
  routes,
});

// // 添加路由守卫
// router.beforeEach((to, from, next) => {
//   const requiresAuth = to.matched.some(record => record.meta.requiresAuth);
//   const isAuthenticated = localStorage.getItem('token'); // 假设使用token存储认证状态

//   if (requiresAuth && !isAuthenticated) {
//     next('/');
//   } else {
//     next();
//   }
// });

export default router;